home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4702 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.8 KB  |  60 lines

  1. Path: news1.h1.usa.pipeline.com!usenet
  2. From: grantp@usa.pipeline.com(Pete)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Need help on using ODBC databased from Visual C++
  5. Date: 31 Jan 1996 18:14:34 GMT
  6. Organization: Kalevi, Inc.
  7. Message-ID: <4eobia$nv9@news1.usa.pipeline.com>
  8. NNTP-Posting-Host: pipe4.h1.usa.pipeline.com
  9. X-PipeUser: grantp
  10. X-PipeHub: usa.pipeline.com
  11. X-PipeGCOS: (Pete)
  12. X-Newsreader: Pipeline USA v3.3.0
  13.  
  14. On Jan 31, 1996 16:49:41 in article <Need help on using ODBC databased from
  15. Visual C++>, 'bassett@tenet.edu' wrote: 
  16.  
  17.  
  18. >We what to open a MicroSoft Access database with more than one table in  
  19. >it. We want to open the database once but open and close the various  
  20. >tables in the database. How is this done. Currently we are able to access 
  21.  
  22. >the various tables in our database using the ODBC drivers that come with  
  23. >Visual C++ 1.5 but when we do a database close it closes the entire  
  24. >database where we just want to close the particular table in the  
  25. >database. HELP. 
  26. I'm only familiar with MFC's ODBC classes in versions 2.2 and above, but 
  27. chances are that it's the same in 1.5x. 
  28.  
  29. What I normally do is insert a CDatabase object as a member of 
  30. my application class: 
  31.   CMyWinApp : public CWinApp 
  32.     { ..... 
  33.        CDatabase mydb; 
  34.        public: 
  35.          CDatabase *  GetDb() { return &mydb; } 
  36.      .... 
  37.  
  38. Define a global function for convenience: 
  39.  
  40. CDatabase * GetDatabase() 
  41.  { return ((CMyApp*)AfxGetApp())->GetDb(); } 
  42.  
  43. Then, I open it in my InitInstance for the application. 
  44.  
  45. When creating instances of CRecordset-derived classes, pass 
  46. the database pointer as the optional arg: 
  47.  
  48.   CMyRecordset rs(GetDatabase()); 
  49.  
  50. That should do it. 
  51.  
  52. WARNING!  All sample code typed in from memory.  May contain 
  53. minor errors. 
  54.  
  55. -- 
  56. Pete Grant 
  57. Kalevi, Inc. 
  58. Object Oriented Software Development
  59.